import React, {Component} from 'react';
import {inject,observer} from "mobx-react";
import loadable from "@loadable/component";
import {Route,Redirect,Switch} from "react-router-dom";

import Commodity from "./CommodityManagement/commodity"
import Commoditywarehousing from "./CommodityManagement/commoditywarehousing"
import Inventorystatistics from "./CommodityManagement/inventorystatistics"
import Purchasereturn from "./CommodityManagement/purchasereturn"
import GoodsDownMaterial from "./CommodityManagement/goodsDownMaterial";
import GoodsWarehousing from "./CommodityManagement/goodsWarehousing";
import StoresAllocating from "./CommodityManagement/storesAllocating";
import StoreSeturn from "./CommodityManagement/storeSeturn";
import Distributiondelivery from "./CommodityManagement/Distributiondelivery";

@inject('user')
@observer
class PrivateRoute extends Component {
    bingRoute(list){
        let arr=[]
        list.forEach((item)=>{
            arr.push(<Route key={item.Id} path={item.routerUrl} component={
                loadable(
                    () => {
                        return import('./' + item.componentPath)
                    }
                )
            }>
            </Route>)

        })
        return arr;
    }
    render() {
        return (
            <Switch>
                {this.bingRoute(this.props.user.routerurl)}
                <Route path={'/index/commodity'} component={Commodity}></Route>
                <Route path={'/index/commoditywarehousing'} component={Commoditywarehousing}></Route>
                <Route path={'/index/inventorystatistics'} component={Inventorystatistics}></Route>
                <Route path={'/index/purchasereturn'} component={Purchasereturn}></Route>
                <Route path={'/index/distributiondelivery'} component={Distributiondelivery}></Route>
                <Route path={'/index/goodsDownMaterial'} component={GoodsDownMaterial}></Route>
                <Route path={'/index/goodsWarehousing'} component={GoodsWarehousing}></Route>
                <Route path={'/index/storeSeturn'} component={StoreSeturn}></Route>
                <Route path={'/index/storesAllocating'} component={StoresAllocating}></Route>

                <Redirect to={'/index/shouye'}></Redirect>
            </Switch>
        );
    }
}

export default PrivateRoute;